package com.siboxuetang.need.web;

import com.siboxuetang.need.vo.ResultBean;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.stereotype.Controller;

import static com.siboxuetang.need.util.ResultCode.NORMAL_ERROR;
import static com.siboxuetang.need.util.ResultCode.SUCCESS;

/**
 * Create Time: 2018年04月25日 22:14
 *
 * @author fin
 */
@Controller
public class BaseCtrl {

    private Logger logger = LogManager.getLogger(getClass().getSimpleName());

    protected void catching(Throwable throwable) {
        logger.catching(throwable);
    }

    protected void debug(String s) {
        logger.debug(s);
    }

    protected void debug(String s, Object... objects) {
        logger.debug(s, objects);
    }

    protected void error(String s) {
        logger.error(s);
    }

    protected void error(String s, Object... objects) {
        logger.error(s, objects);
    }

    protected void error(String s, Throwable throwable) {
        logger.error(s, throwable);
    }

    protected void info(String s) {
        logger.info(s);
    }

    protected void info(String s, Object... objects) {
        logger.info(s, objects);
    }

    public ResultBean baseResponse(Object data, Integer status, String error){
        return new ResultBean(status, data, error);
    }

    public ResultBean success(Object data){
        return baseResponse(data, SUCCESS, null);
    }

    public ResultBean success(){
        return success(null);
    }

    public ResultBean err(Integer status, String error){
        return baseResponse(null, status, error);
    }

    public ResultBean err(Integer status) {
        return err(status, null);
    }

    public ResultBean err(String error){
        return err(NORMAL_ERROR, error);
    }

    public ResultBean err(){
        return err(NORMAL_ERROR);
    }
}
